//    Copyright (C) Kherty.  All rights reserved.
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;

namespace OpenLS.Chart.UI
{
    class CountAndGroupingToZMaximumConverter: IMultiValueConverter
    {
        #region IMultiValueConverter Members

        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            if (values[0] == DependencyProperty.UnsetValue)
                return System.Convert.ChangeType(1, targetType);
            int count = (int) values[0];
            BarGrouping grouping;
            if (values[1] is Grouping)
            {
                switch ((Grouping)values[1])
                {
                    case Grouping.PercentStacked:
                        grouping = BarGrouping.PercentStacked;
                        break;
                        case Grouping.Stacked:
                        grouping = BarGrouping.Stacked;
                        break;
                        case Grouping.Standard:
                        grouping = BarGrouping.Stacked;
                        break;
                        default: throw new NotSupportedException();
                }
            }
            else if (values[1] is BarGrouping)
            {
                grouping = (BarGrouping) values[1];
            }
            else 
                throw new NotSupportedException();
            switch(grouping)
            {
                case BarGrouping.Clustered:
                    case BarGrouping.PercentStacked:
                    case BarGrouping.Stacked:
                    return System.Convert.ChangeType(1, targetType);
                    case BarGrouping.Standard:
                    return System.Convert.ChangeType(count, targetType);
                    default: throw new NotSupportedException();
            }
        }

        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
        {
            throw new NotSupportedException();
        }

        #endregion
    }
}
